package hcmut.edu.vn.helps;

import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;

public class QuickSortAlgorithm {	
	
	public static void QuickSort(List<Cloudlet> list, int left, int right ) {
		int i = left;
		int j = right;
		Cloudlet x = list.get((left + right)/2);
		while (i<=j) {
			while (list.get(i).getCloudletId() < x.getCloudletId()) {
				i++;
			}
			while (list.get(j).getCloudletId() > x.getCloudletId()) {
				j--;
			}
			if (i<=j) {				
				swap(list.get(i),list.get(j));
				
				i++;
				j--;
			}
		}
		if (left < j) {
			QuickSort(list, left, j);
		}
		if (right > i) {
			QuickSort(list, i, right);
		}
	}
	
	public static void swap(Cloudlet cloudlet1, Cloudlet cloudlet2) {
		Cloudlet temp = cloudlet1;
		cloudlet1 = cloudlet2;
		cloudlet2 = temp;
		
	}	
	
}

